import request from '@/config/axios'

// 钉钉角色 VO
export interface DingtalkRoleVO {
  id: number // 主键
  createUserName: string // 创建人名称
  updateUserName: string // 更新人名称
  deptId: number // 部门id
  deptName: string // 部门名称
  userId: number // 系统用户id
  dingtalkId: number // 钉钉id
  roleName: string // 角色名称
  parentId: number // 父节点id(角色组id)
  groupFlag: number // 角色组标识（0：角色，1：角色组）
}

// 钉钉角色 API
export const DingtalkRoleApi = {
  // 查询钉钉角色分页
  getDingtalkRolePage: async (params: any) => {
    return await request.get({ url: `/business/dingtalk-role/page`, params })
  },

  // 查询钉钉角色分页
  getDingtalkRoleList: async (params: any) => {
    return await request.get({ url: `/business/dingtalk-role/list`, params })
  },

  // 查询钉钉角色详情
  getDingtalkRole: async (id: number) => {
    return await request.get({ url: `/business/dingtalk-role/get?id=` + id })
  },

  // 新增钉钉角色
  createDingtalkRole: async (data: DingtalkRoleVO) => {
    return await request.post({ url: `/business/dingtalk-role/create`, data })
  },

  // 修改钉钉角色
  updateDingtalkRole: async (data: DingtalkRoleVO) => {
    return await request.post({ url: `/business/dingtalk-role/update`, data })
  },

  // 删除钉钉角色
  deleteDingtalkRole: async (id: number) => {
    return await request.get({ url: `/business/dingtalk-role/delete?id=` + id })
  },

  // 导出钉钉角色 Excel
  exportDingtalkRole: async (params) => {
    return await request.download({ url: `/business/dingtalk-role/export-excel`, params })
  },

// ==================== 子表（用户和钉钉角色关联） ====================

  // 获得用户和钉钉角色关联列表
  getDingtalkUserRoleListByRoleId: async (roleId) => {
    return await request.get({ url: `/business/dingtalk-role/dingtalk-user-role/list-by-role-id?roleId=` + roleId })
  },

  // 同步钉钉角色数据
  initDingtalk: async () => {
    return await request.post({ url: `/business/dingtalk-role/init` })
  },
}
